//
//  goodsViewController.m
//  iOS-LoginUIController
//
//  Created by Apple-19 on 15/10/12.
//  Copyright (c) 2015年 Apple-19. All rights reserved.
//

#import "goodsViewController.h"
#import "SDRefresh.h"
#import "AppDelegate.h"
#import "WebViewController.h"
#import "LocationViewController.h"
//#import "ViewController.h"
@interface goodsViewController ()

@property (nonatomic, weak) SDRefreshFooterView *refreshFooter;
@property (nonatomic, weak) SDRefreshHeaderView *refreshHeader;
@property (nonatomic, assign) NSInteger totalRowCount;


@property (nonatomic, weak) UIImageView *animationView;
@property (nonatomic, weak) UIImageView *boxView;
@property (nonatomic, weak) UILabel *label;

@property (nonatomic,strong) UITapGestureRecognizer *dismissMoreViewRecognizer;


@end

@implementation goodsViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.cataDic=[[NSMutableDictionary alloc] init];
    self.cataArr4=[NSMutableArray array];
    self.cataArr=[NSMutableArray arrayWithObjects:@"类别",@"价格",@"其他", nil];
    self.cataArr1=[NSMutableArray arrayWithObjects:@"手办",@"公仔", nil];
    self.cataArr2=[NSMutableArray arrayWithObjects:@"0～50",@"50～150",@"150～300", nil];
    [self.cataDic setObject:self.cataArr1 forKey:[self.cataArr objectAtIndex:0]];
    [self.cataDic setObject:self.cataArr2 forKey:[self.cataArr objectAtIndex:1]];
    self.threeArr=[NSMutableArray arrayWithObjects:@"全部",@"男士",@"女士", @"儿童", nil];
    self.listArr1=[NSMutableArray arrayWithObjects:@"衬衫",@"休闲裤",@"鞋子", @"西服",@"运动衣", nil];
    self.listArr2=[NSMutableArray arrayWithObjects:@"外衣",@"高跟鞋",@"正装", @"休闲鞋",@"运动衣", nil];
    self.listArr3=[NSMutableArray arrayWithObjects:@"玩具",@"巴拉巴拉",@"ONEPIECE",@"七武海", nil];
    self.listDic=[[NSMutableDictionary alloc] init];
    [self.listDic setObject:self.listArr1 forKey:[self.threeArr objectAtIndex:1]];
    [self.listDic setObject:self.listArr2 forKey:[self.threeArr objectAtIndex:2]];
    [self.listDic setObject:self.listArr3 forKey:[self.threeArr objectAtIndex:3]];
    self.listArr=[NSMutableArray array];
    self.goodsShowView.tableFooterView=[[UIView alloc]init];
    self.oneTableView.tableFooterView=[[UIView alloc]init];
    self.twoTableView.tableFooterView=[[UIView alloc]init];
    self.threeTableView.tableFooterView=[[UIView alloc]init];
    self.fourTableView.tableFooterView=[[UIView alloc]init];
    // Do any additional setup after loading the view from its nib
    i=8;
    
    [self.view sizeToFit];
//    self.searchBox=[[UISearchController alloc]initWithSearchResultsController:nil];
//    self.searchBox.searchBar.delegate=self;
//    self.searchBox.searchResultsUpdater=self;
//    self.searchBox.dimsBackgroundDuringPresentation=NO;
//    self.searchBox.searchBar.barTintColor=[UIColor colorWithRed:0.1 green:0.5 blue:1 alpha:1];
//    [searchView addSubview:self.searchBox.searchBar];
//    [self.searchBox.searchBar sizeToFit];
    self.searchBar.delegate = self;
    
    NSString *path=[[NSBundle mainBundle] pathForResource:@"goods" ofType:@"plist"];
    self.sourceGoods=(NSMutableArray *)[NSArray arrayWithContentsOfFile:path];
    
    self.cellNib=[UINib nibWithNibName:@"goodsTableViewCell" bundle:nil];
    
    self.dismissMoreViewRecognizer.enabled=NO;
    self.dismissMoreViewRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissMoreView:)];
    [self.view addGestureRecognizer: self.dismissMoreViewRecognizer];
    myView.hidden=YES;
    twoView.hidden=YES;
    [self.view addSubview:myView];
    [self.view addSubview:twoView];
    
    user1=[NSUserDefaults standardUserDefaults];
    
    [self setupFooter];
    [self setupHeader];
}
-(void)viewWillAppear:(BOOL)animated
{
    [self.goodsShowView reloadData];
    twoView.hidden=YES;
    addSomeView.hidden=YES;
//    if ([user1 objectForKey:@"username"]==NULL || [user1 objectForKey:@"password"]==NULL) {
////        locationButton.hidden=YES;
////        informationButton.hidden=YES;
////        shareButton.hidden=YES;
////        [loginButton setTitle:@"   登录" forState:UIControlStateNormal];
////    
////        CGRect oriFrame=myView.frame;
////        oriFrame.origin.y-=210;
////        myView.frame=oriFrame;
////        [self.goodsShowView addSubview:myView];
//        twoView.hidden=NO;
//    }else
//        myView.hidden=YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)dismissMoreView:(id)sender{
    if ([user1 objectForKey:@"username"]==NULL || [user1 objectForKey:@"password"]==NULL) {
        twoView.hidden=YES;
    }else
        myView.hidden=YES;
    
    addSomeView.hidden=YES;
    self.dismissMoreViewRecognizer.enabled=NO;
}
-(IBAction)titleButton:(id)sender{
    addSomeView.hidden=YES;
    if ([user1 objectForKey:@"username"]==NULL || [user1 objectForKey:@"password"]==NULL) {
        //myView.hidden=YES;
        if (twoView.hidden==YES) {
            twoView.hidden=NO;
            [UIView animateWithDuration:0.1 animations:^{} completion:^(BOOL finished) {
                self.dismissMoreViewRecognizer.enabled=YES;
                
            }];
        }else{
            twoView.hidden=YES;
            self.dismissMoreViewRecognizer.enabled=NO;
        }

    }else
        //twoView.hidden=YES;
        if (myView.hidden==YES) {
            myView.hidden=NO;
            [UIView animateWithDuration:0.1 animations:^{} completion:^(BOOL finished) {
                self.dismissMoreViewRecognizer.enabled=YES;

            }];
        }else{
            myView.hidden=YES;
            self.dismissMoreViewRecognizer.enabled=NO;
        }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [self.searchBar resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    
    NSString *searchString = self.searchBar.text;
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title contains [c] %@", searchString];
    self.filterGoods = [NSMutableArray arrayWithArray:[self.sourceGoods filteredArrayUsingPredicate:predicate]];
    [self.goodsShowView reloadData];
    return YES;
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if(string==nil||[string isEqualToString:@""])
    {
        self.filterGoods  = [NSMutableArray array];
        [self.goodsShowView reloadData];
    }
    return YES;
}
- (IBAction)searchButton:(id)sender {
    NSString *searchString = self.searchBar.text;
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title contains [c] %@", searchString];
    self.filterGoods = [NSMutableArray arrayWithArray:[self.sourceGoods filteredArrayUsingPredicate:predicate]];
    [self.goodsShowView reloadData];
    [self textFieldShouldReturn:nil];
}

//返回行数判断
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView==self.goodsShowView) {
        if( self.filterGoods.count>0)
        {
            return self.filterGoods.count;
        }else{
            return i;
        }

    }else if (tableView==self.oneTableView){
        return self.cataArr.count;

    }else if (tableView==self.twoTableView){
        return self.cataArr4.count;
        
    }
    else if (tableView==self.threeTableView){
        return self.threeArr.count;
        
    }else if (tableView==self.fourTableView){
        return self.listArr.count;
    }
    else {
        return 1;
    }
}

//搜索
//-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
//{
//    NSPredicate *predicate=[NSPredicate predicateWithFormat:@"title contains [c] %@",self.searchBox.searchBar.text];
//    self.filterGoods=[NSMutableArray arrayWithArray:[self.sourceGoods filteredArrayUsingPredicate:predicate]];
//    [self.goodsShowView reloadData];
//}

//tableView显示

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==self.goodsShowView) {
        static NSString *cellStr=@"Cell";
        goodsTableViewCell *cell=(goodsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellStr];
        if(cell==nil)
        {
            [self.cellNib instantiateWithOwner:self options:nil];
            cell=self.myGoodsCell;
            self.myGoodsCell=nil;
        }
        if(self.filterGoods.count>0)
        {
            NSDictionary *dict=[self.filterGoods objectAtIndex:indexPath.row];
            cell.title.text=dict[@"title"];
            cell.icon.image=[UIImage imageNamed:dict[@"icon"]];
            cell.price.text=[NSString stringWithFormat:@"￥%@",dict[@"price"]];
            cell.comment.text=[NSString stringWithFormat:@"好评%@",dict[@"comment"]];
            cell.purchaseNum.text=[NSString stringWithFormat:@"已有%@人购买",dict[@"purchaseNum"]];
        }else
        {
            NSDictionary *dict=[self.sourceGoods objectAtIndex:indexPath.row];
            cell.title.text=dict[@"title"];
            cell.icon.image=[UIImage imageNamed:dict[@"icon"]];
            cell.price.text=[NSString stringWithFormat:@"￥%@",dict[@"price"]];
            cell.comment.text=[NSString stringWithFormat:@"好评%@",dict[@"comment"]];
            cell.purchaseNum.text=[NSString stringWithFormat:@"已有%@人购买",dict[@"purchaseNum"]];
        }
        //    右边小图标
        //    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        //    [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
        return cell;

    }else if (tableView==self.oneTableView){
        static NSString *cellStr = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        }
        NSString *menu = (NSString *)[self.cataArr objectAtIndex:indexPath.row];
        cell.textLabel.text = menu;
        return cell;
        
    }
    else if (tableView==self.twoTableView){
        static NSString *cellStr = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        }
        NSString *menu = (NSString *)[self.cataArr4 objectAtIndex:indexPath.row];
        cell.textLabel.text = menu;
        cell.backgroundColor=[UIColor lightGrayColor];

        self.twoTableView.backgroundColor=[UIColor lightGrayColor];
        return cell;

    }else if (tableView==self.fourTableView){
        static NSString *cellStr = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        }
        NSString *menu = (NSString *)[self.listArr objectAtIndex:indexPath.row];
        cell.textLabel.text = menu;
        cell.backgroundColor=[UIColor lightGrayColor];
        return cell;
        
    }else if (tableView==self.threeTableView){
        static NSString *cellStr = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        }
        NSString *menu = (NSString *)[self.threeArr objectAtIndex:indexPath.row];
        cell.textLabel.text = menu;
        self.fourTableView.backgroundColor=[UIColor lightGrayColor];
        return cell;
        
    }else if (tableView==self.fourTableView){
        static NSString *cellStr = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        }
        NSString *menu = (NSString *)[self.listArr objectAtIndex:indexPath.row];
        cell.textLabel.text = menu;
        cell.backgroundColor=[UIColor lightGrayColor];
        return cell;
        
    }


    else{
        return nil;
    }
}
//单元格高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==self.goodsShowView) {
        return 120;

    }else if (tableView==self.oneTableView){
        return 50;
    }else if (tableView==self.twoTableView){
        return 50;
    }else if (tableView==self.threeTableView){
        return 40;
    }else if (tableView==self.fourTableView){
        return 40;
    }
    else{
        return 30;
    }
}

//返回按钮
//- (IBAction)goToBack {
////    ViewController *view=[[ViewController alloc]init];
////    view.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
////    
////    [self presentViewController:view animated:YES completion:nil];
//    
//    [self dismissViewControllerAnimated:YES completion:nil];
//}
//点击单元格
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.goodsShowView deselectRowAtIndexPath:indexPath animated:YES];

    if (tableView==self.goodsShowView) {
        if (addSomeView.hidden==NO) {
            addSomeView.hidden=YES;
        }else{
            
        informations =[[InformationsOfGoodViewController alloc]init];
        
        if( self.filterGoods.count>0)
        {
            //self.searchBox.active=NO;
            
            NSDictionary *dictionary=[self.filterGoods objectAtIndex:indexPath.row];
            informations.dict=dictionary;
            informations.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
        }else{
            NSDictionary *dictionary=[self.sourceGoods objectAtIndex:indexPath.row];
            informations.dict=dictionary;
            informations.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
        }
        [self presentViewController:informations animated:YES completion:nil];
        }

    }else if (tableView==self.oneTableView){
        NSString *list=[self.cataArr objectAtIndex:indexPath.row];
        self.cataArr4=[self.cataDic objectForKey:list];
        [self.twoTableView reloadData];

    }else if (tableView==self.twoTableView){
        NSArray *priceArr=[NSArray array];
        NSString *list=[self.cataArr4 objectAtIndex:indexPath.row];
        if ([list containsString:@"~"]) {
            priceArr=[list componentsSeparatedByString:@"~"];
        }
        NSString *from=[priceArr objectAtIndex:0];
        NSString *to=[priceArr objectAtIndex:1];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"price.intValue >%d and price.intValue <%d", from.intValue,to.intValue];
        self.filterGoods = [NSMutableArray arrayWithArray:[self.sourceGoods filteredArrayUsingPredicate:predicate]];
        [self.goodsShowView reloadData];
        addSomeView.hidden=YES;
    }
    else if (tableView==self.threeTableView){
        NSString *list=[self.threeArr objectAtIndex:indexPath.row];
        self.listArr=[self.listDic objectForKey:list];
        [self.fourTableView reloadData];
    }else if (tableView==self.fourTableView){
        
        NSString *list=[self.listArr objectAtIndex:indexPath.row];
        NSLog(@"-------%@",list);
        self.filterGoods=[NSMutableArray array];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title contains [c] %@", list];
        self.filterGoods = [NSMutableArray arrayWithArray:[self.sourceGoods filteredArrayUsingPredicate:predicate]];
        [self.goodsShowView reloadData];
        addSomeView.hidden=YES;
    }

//    }
}

-(IBAction)toLocation:(id)sender{
    LocationViewController *location=[[LocationViewController alloc] init];
    [self presentViewController:location animated:YES completion:nil];
}

-(IBAction)toMy:(id)sender{
    MyViewController *myNext=[[MyViewController alloc]init];
    [self presentViewController:myNext animated:YES completion:nil];
}

-(IBAction)toURL:(id)sender{
    UIAlertView *alter=nil;
    alter=[[UIAlertView alloc]initWithTitle:@"提示" message:@"是否跳转" delegate:self cancelButtonTitle:nil otherButtonTitles:@"是", @"否", nil];
    alter.tag=10;
    [alter show];
}
//退出程序
-(IBAction)exitButton:(id)sender{
    if ([user1 objectForKey:@"username"]==NULL || [user1 objectForKey:@"password"]==NULL){
        
        UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *mainView=[story instantiateViewControllerWithIdentifier:@"viewController"];
        
        [self presentViewController:mainView animated:YES completion:nil];
    }else{
    UIAlertView *alter=nil;
    alter=[[UIAlertView alloc]initWithTitle:@"提示" message:@"是否退出" delegate:self cancelButtonTitle:nil otherButtonTitles:@"是", @"否", nil];
    alter.tag=11;
    [alter show];
    }
    
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex==0) {
        if(alertView.tag==10){
            WebViewController *webView=[[WebViewController alloc]init];
            [self presentViewController:webView animated:YES completion:nil];

        }else{
        [user1 setObject:NULL forKey:@"username"];
        [user1 setObject:NULL forKey:@"password"];
        
        
        AppDelegate *app=[UIApplication sharedApplication].delegate;
        UIWindow *window =app.window;
        
        [UIView animateWithDuration:1.0 animations:^{
            window.alpha=0;
            window.frame=CGRectMake(0, window.bounds.size.width, 0, 0);
        }completion:^(BOOL finished){
            exit(0);
        }];
        }
    }
}

//下拉
- (void)setupFooter
{
    SDRefreshFooterView *refreshFooter = [SDRefreshFooterView refreshViewWithStyle:SDRefreshViewStyleClassical];
    [refreshFooter addToScrollView:self.goodsShowView];
    [refreshFooter addTarget:self refreshAction:@selector(footerRefresh)];
    _refreshFooter = refreshFooter;
}
- (void)footerRefresh
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.totalRowCount += 2;
        i+=2;
        if (i<15) {
            [self.goodsShowView reloadData];
        }
        
        [self.refreshFooter endRefreshing];
    });
}

//上拉
- (void)setupHeader
{
    SDRefreshHeaderView *refreshHeader = [SDRefreshHeaderView refreshViewWithStyle:SDRefreshViewStyleCustom];
    
    // 默认是在navigationController环境下，如果不是在此环境下，请设置 refreshHeader.isEffectedByNavigationController = NO;
    [refreshHeader addToScrollView:self.goodsShowView];
    _refreshHeader = refreshHeader;
    
    __weak SDRefreshHeaderView *weakRefreshHeader = refreshHeader;
    refreshHeader.beginRefreshingOperation = ^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.totalRowCount += 3;
            [self.goodsShowView reloadData];
            [weakRefreshHeader endRefreshing];
        });
    };
    
    // 动画view
    UIImageView *animationView = [[UIImageView alloc] init];
    animationView.frame = CGRectMake(30, 45, 40, 40);
    animationView.image = [UIImage imageNamed:@"staticDeliveryStaff"];
    [refreshHeader addSubview:animationView];
    _animationView = animationView;
    
    UIImageView *boxView = [[UIImageView alloc] init];
    boxView.frame = CGRectMake(150, 10, 15, 8);
    boxView.image = [UIImage imageNamed:@"box"];
    [refreshHeader addSubview:boxView];
    _boxView = boxView;
    
    UILabel *label= [[UILabel alloc] init];
    label.text = @"下拉加载最新数据";
    label.frame = CGRectMake((self.view.bounds.size.width - 200) * 0.5, 5, 200, 20);
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:14];
    label.textAlignment = NSTextAlignmentCenter;
    [refreshHeader addSubview:label];
    _label = label;
    
    // normal状态执行的操作
    refreshHeader.normalStateOperationBlock = ^(SDRefreshView *refreshView, CGFloat progress){
        refreshView.hidden = NO;
        if (progress == 0) {
            _animationView.transform = CGAffineTransformMakeScale(0.1, 0.1);
            _boxView.hidden = NO;
            _label.text = @"下拉加载最新数据";
            [_animationView stopAnimating];
        }
        
        self.animationView.transform = CGAffineTransformConcat(CGAffineTransformMakeTranslation(progress * 10, -20 * progress), CGAffineTransformMakeScale(progress, progress));
        self.boxView.transform = CGAffineTransformMakeTranslation(- progress * 90, progress * 35);
    };
    
    // willRefresh状态执行的操作
    refreshHeader.willRefreshStateOperationBlock = ^(SDRefreshView *refreshView, CGFloat progress){
        _boxView.hidden = YES;
        _label.text = @"放开我，我要为你加载数据";
        _animationView.transform = CGAffineTransformConcat(CGAffineTransformMakeTranslation(10, -20), CGAffineTransformMakeScale(1, 1));
        NSArray *images = @[[UIImage imageNamed:@"deliveryStaff0"],
                            [UIImage imageNamed:@"deliveryStaff1"],
                            [UIImage imageNamed:@"deliveryStaff2"],
                            [UIImage imageNamed:@"deliveryStaff3"]
                            ];
        _animationView.animationImages = images;
        [_animationView startAnimating];
    };
    
    // refreshing状态执行的操作
    refreshHeader.refreshingStateOperationBlock = ^(SDRefreshView *refreshView, CGFloat progress){
        _label.text = @"客观别急，正在加载数据...";
        [UIView animateWithDuration:1.5 animations:^{
            self.animationView.transform = CGAffineTransformMakeTranslation(200, -20);
        }];
    };
    
    // 进入页面自动加载一次数据
    [refreshHeader beginRefreshing];
}

-(IBAction)toView:(id)sender{
    UIButton *button=sender;
    switch (button.tag) {
        case 0:
            [addSomeView addSubview:distanceView];
            [nearbyView removeFromSuperview];
            [cataView removeFromSuperview];
            if (addSomeView.hidden==NO) {
                addSomeView.hidden=YES;
            }else{
                addSomeView.hidden=NO;
                [UIView animateWithDuration:0.1 animations:^{} completion:^(BOOL finished) {
                    self.dismissMoreViewRecognizer.enabled=YES;
                    
                }];

            }
            break;
        case 1:
            [distanceView removeFromSuperview];
            [nearbyView removeFromSuperview];
            [addSomeView addSubview:cataView];
            if (addSomeView.hidden==NO) {
                addSomeView.hidden=YES;
            }else{
                addSomeView.hidden=NO;
                [UIView animateWithDuration:0.1 animations:^{} completion:^(BOOL finished) {
                    self.dismissMoreViewRecognizer.enabled=NO;
                    
                }];
                
            }
            break;
        case 2:
            [distanceView removeFromSuperview];
            [cataView removeFromSuperview];
            [addSomeView addSubview:nearbyView];
            if (addSomeView.hidden==NO) {
                addSomeView.hidden=YES;
            }else{
                addSomeView.hidden=NO;
                [UIView animateWithDuration:0.1 animations:^{} completion:^(BOOL finished) {
                    self.dismissMoreViewRecognizer.enabled=NO;
                    
                }];
                
            }
            break;
        default:
            break;
    }
}

-(IBAction)showDistance:(UIButton *)sender{
    for (UIView *view in sender.superview.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            ((UIButton *)view).selected=NO;
        }
    }
    sender.selected=YES;
    
    NSString *radius=[NSString stringWithFormat:@"%ld",(long)sender.tag];
    [distanceButton setTitle:[radius stringByAppendingString:@"米"] forState:UIControlStateNormal];
    
    //[self hideSelected];
}

#pragma mark - Configuring the view’s layout behavior

- (BOOL)prefersStatusBarHidden
{
    return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

#pragma mark - ICSDrawerControllerPresenting

- (void)drawerControllerWillOpen:(ICSDrawerController *)drawerController
{
    self.view.userInteractionEnabled = NO;
}

- (void)drawerControllerDidClose:(ICSDrawerController *)drawerController
{
    self.view.userInteractionEnabled = YES;
}

#pragma mark - Open drawer button

- (IBAction)openDrawer:(id)sender
{
    [self.drawer open];
}


@end
